
export function uploadFile(url,file_name,file_path) {
   return new Promise((resolve, reject)=>{
    wx.uploadFile({
      filePath: file_path,
      name: file_name,
      url: getApp().globalData.apiBaseUrl+url,
      header:{
        'Content-Type': 'application/json',
        "token": getApp().globalData.token,
      },
      success:(res)=>{
        let json=JSON.parse(res.data)
        console.log("上传文件->"+res.data)
        if(json.code==0){
          resolve(json)
        }else{
          reject(json['msg'])
        }
      },
      fail:(err)=>{
        console.log("上传文件异常->"+JSON.stringify(err))
        reject(err.errMsg)
      }
    })
   })
}

export function postData(url,params){  
 // console.log(getApp().globalData.apiBaseUrl);
  let path=getApp().globalData.apiBaseUrl+url
  console.log("------------start-----------\nparams="+JSON.stringify(params)+"\n----------end----------")
  return new Promise((resolve, reject)=>{
    wx.request({
      url:path,
      method: 'post',
      header:{
        'Content-Type': 'application/json',
        "token": getApp().globalData.token,
       // "User-Agent":"android-v2."+"2.5.9"
      },
      data:params,
      success: (res) => {
         let data=res.data;
         console.log("成功->"+JSON.stringify(data))
         if(data.code==0){
           resolve(data) 
         }else{
           reject(data)
         }
      },
      fail:(err)=>{
        console.log("异常->"+res.data)
        reject(err)
      }
    })
  })
}

